package com.mgq.netty.chat.config;

import com.mgq.netty.chat.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author MaGuangQi
 * @description
 * @date 2021-12-09 16:38
 **/
public abstract class ConfigProperties {
    static Properties properties;
    static {
        try(InputStream in = ConfigProperties.class.getResourceAsStream("/application.properties")){

            properties = new Properties();
            properties.load(in);

        } catch (IOException e){

            throw new ExceptionInInitializerError(e);
        }
    }
    public static int getServerPort(){
        final String value = properties.getProperty("server.port");

        if(value == null)
        {
            return 8080;
        }else{
            return Integer.parseInt(value);
        }
    }

    public static Serializer.Algorithm getSerializerAlgorithm() {
        final String value = properties.getProperty("serializer.algorithm");
        if (value == null) {
            return Serializer.Algorithm.Java;
        }
        return Serializer.Algorithm.valueOf(value);
    }
}
